/**
 *
 */
import OpenApi;
import OpenApi.OpenApiUtil;

extends OpenApi;


init(config: OpenApiUtil.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('httpdns', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!$isNull(endpoint)) {
    return endpoint;
  }
  
  if (!$isNull(endpointMap) && !$isNull(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AddDomainRequest {
  accountId?: string(name='AccountId', example='123456'),
  domainName?: string(name='DomainName', description='This parameter is required.', example='www.example.com'),
}

model AddDomainResponseBody = {
  domainName?: string(name='DomainName', example='www.example.com'),
  requestId?: string(name='RequestId', example='ADA27798-6911-4B06-AF34-53F62F62XXXX'),
}

model AddDomainResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: AddDomainResponseBody(name='body'),
}

/**
 * @summary 添加域名
 *
 * @param request AddDomainRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return AddDomainResponse
 */
async function addDomainWithOptions(request: AddDomainRequest, runtime: $RuntimeOptions): AddDomainResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.accountId)) {
    query['AccountId'] = request.accountId;
  }
  if (!$isNull(request.domainName)) {
    query['DomainName'] = request.domainName;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'AddDomain',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 添加域名
 *
 * @param request AddDomainRequest
 * @return AddDomainResponse
 */
async function addDomain(request: AddDomainRequest): AddDomainResponse {
  var runtime = new $RuntimeOptions{};
  return addDomainWithOptions(request, runtime);
}

model DeleteDomainRequest {
  accountId?: string(name='AccountId', example='12****'),
  domainName?: string(name='DomainName', description='This parameter is required.', example='www.example.com'),
}

model DeleteDomainResponseBody = {
  domainName?: string(name='DomainName', example='www.example.com'),
  requestId?: string(name='RequestId', example='FA8C2599-362D-4113-8FB4-E88A40C2****'),
}

model DeleteDomainResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: DeleteDomainResponseBody(name='body'),
}

/**
 * @summary 删除域名
 *
 * @param request DeleteDomainRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return DeleteDomainResponse
 */
async function deleteDomainWithOptions(request: DeleteDomainRequest, runtime: $RuntimeOptions): DeleteDomainResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.accountId)) {
    query['AccountId'] = request.accountId;
  }
  if (!$isNull(request.domainName)) {
    query['DomainName'] = request.domainName;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'DeleteDomain',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 删除域名
 *
 * @param request DeleteDomainRequest
 * @return DeleteDomainResponse
 */
async function deleteDomain(request: DeleteDomainRequest): DeleteDomainResponse {
  var runtime = new $RuntimeOptions{};
  return deleteDomainWithOptions(request, runtime);
}

model DescribeDomainsRequest {
  accountId?: string(name='AccountId', example='123456'),
  pageNumber?: long(name='PageNumber', example='1'),
  pageSize?: long(name='PageSize', example='10'),
}

model DescribeDomainsResponseBody = {
  domains?: {
    domain?: [ 
    {
      domainName?: string(name='DomainName', example='www.aliyun.com'),
    }
  ](name='Domain')
  }(name='Domains'),
  pageNumber?: long(name='PageNumber', example='1'),
  pageSize?: long(name='PageSize', example='20'),
  requestId?: string(name='RequestId', example='A6B3BB61-69CB-50E0-9DC0-0C1658D44A47'),
  totalCount?: long(name='TotalCount', example='12'),
}

model DescribeDomainsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: DescribeDomainsResponseBody(name='body'),
}

/**
 * @param request DescribeDomainsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return DescribeDomainsResponse
 */
async function describeDomainsWithOptions(request: DescribeDomainsRequest, runtime: $RuntimeOptions): DescribeDomainsResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.accountId)) {
    query['AccountId'] = request.accountId;
  }
  if (!$isNull(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!$isNull(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'DescribeDomains',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @param request DescribeDomainsRequest
 * @return DescribeDomainsResponse
 */
async function describeDomains(request: DescribeDomainsRequest): DescribeDomainsResponse {
  var runtime = new $RuntimeOptions{};
  return describeDomainsWithOptions(request, runtime);
}

model GetAccountInfoResponseBody = {
  accountInfo?: {
    accountId?: string(name='AccountId', example='1337****'),
    dohEnabled?: boolean(name='DohEnabled'),
    dohResolveAllEnabled?: boolean(name='DohResolveAllEnabled'),
    monthDohResolveCount?: long(name='MonthDohResolveCount'),
    monthFreeCount?: int32(name='MonthFreeCount', example='1500000'),
    monthHttpAesResolveCount?: long(name='MonthHttpAesResolveCount'),
    monthHttpsAesResolveCount?: long(name='MonthHttpsAesResolveCount'),
    monthHttpsResolveCount?: int32(name='MonthHttpsResolveCount', example='3'),
    monthResolveCount?: int32(name='MonthResolveCount', example='9927326'),
    packageCount?: int32(name='PackageCount', example='0'),
    signSecret?: string(name='SignSecret', example='50F9C40E****'),
    signedCount?: long(name='SignedCount', example='611523'),
    unsignedCount?: long(name='UnsignedCount', example='1523'),
    unsignedEnabled?: boolean(name='UnsignedEnabled', example='true'),
    userStatus?: int32(name='UserStatus', example='1'),
  }(name='AccountInfo'),
  requestId?: string(name='RequestId', example='50F9C40E-188D-4208-BE2C-74271337****'),
}

model GetAccountInfoResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetAccountInfoResponseBody(name='body'),
}

/**
 * @summary 获取用户信息包含配置项
 *
 * @param request GetAccountInfoRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetAccountInfoResponse
 */
async function getAccountInfoWithOptions(runtime: $RuntimeOptions): GetAccountInfoResponse {
  var req = new OpenApiUtil.OpenApiRequest{};
  var params = new OpenApiUtil.Params{
    action = 'GetAccountInfo',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 获取用户信息包含配置项
 *
 * @return GetAccountInfoResponse
 */
async function getAccountInfo(): GetAccountInfoResponse {
  var runtime = new $RuntimeOptions{};
  return getAccountInfoWithOptions(runtime);
}

model GetResolveCountSummaryRequest {
  granularity?: string(name='Granularity', description='This parameter is required.', example='day'),
  timeSpan?: int32(name='TimeSpan', description='This parameter is required.', example='7'),
}

model GetResolveCountSummaryResponseBody = {
  requestId?: string(name='RequestId', example='3106FFF3-3612-542A-B2CD-3CF4CD48****'),
  resolveSummary?: {
    doh?: long(name='Doh'),
    http?: long(name='Http', example='123'),
    http6?: long(name='Http6', example='123'),
    httpAes?: string(name='HttpAes'),
    https?: long(name='Https', example='123'),
    https6?: long(name='Https6', example='123'),
    httpsAes?: string(name='HttpsAes'),
  }(name='ResolveSummary'),
}

model GetResolveCountSummaryResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetResolveCountSummaryResponseBody(name='body'),
}

/**
 * @summary 解析次数概览
 *
 * @param request GetResolveCountSummaryRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetResolveCountSummaryResponse
 */
async function getResolveCountSummaryWithOptions(request: GetResolveCountSummaryRequest, runtime: $RuntimeOptions): GetResolveCountSummaryResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.granularity)) {
    query['Granularity'] = request.granularity;
  }
  if (!$isNull(request.timeSpan)) {
    query['TimeSpan'] = request.timeSpan;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'GetResolveCountSummary',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 解析次数概览
 *
 * @param request GetResolveCountSummaryRequest
 * @return GetResolveCountSummaryResponse
 */
async function getResolveCountSummary(request: GetResolveCountSummaryRequest): GetResolveCountSummaryResponse {
  var runtime = new $RuntimeOptions{};
  return getResolveCountSummaryWithOptions(request, runtime);
}

model GetResolveStatisticsRequest {
  domainName?: string(name='DomainName', description='This parameter is required.', example='www.aliyun.com'),
  granularity?: string(name='Granularity', description='This parameter is required.', example='month'),
  protocolName?: string(name='ProtocolName', example='https'),
  timeSpan?: int32(name='TimeSpan', description='This parameter is required.', example='2'),
}

model GetResolveStatisticsResponseBody = {
  dataPoints?: {
    dataPoint?: [ 
    {
      count?: int32(name='Count', example='9703'),
      time?: int32(name='Time', example='1488297600'),
    }
  ](name='DataPoint')
  }(name='DataPoints'),
  requestId?: string(name='RequestId', example='50F9C40E-188D-B00B-BE2C-7427E531****'),
}

model GetResolveStatisticsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetResolveStatisticsResponseBody(name='body'),
}

/**
 * @param request GetResolveStatisticsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetResolveStatisticsResponse
 */
async function getResolveStatisticsWithOptions(request: GetResolveStatisticsRequest, runtime: $RuntimeOptions): GetResolveStatisticsResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.domainName)) {
    query['DomainName'] = request.domainName;
  }
  if (!$isNull(request.granularity)) {
    query['Granularity'] = request.granularity;
  }
  if (!$isNull(request.protocolName)) {
    query['ProtocolName'] = request.protocolName;
  }
  if (!$isNull(request.timeSpan)) {
    query['TimeSpan'] = request.timeSpan;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'GetResolveStatistics',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @param request GetResolveStatisticsRequest
 * @return GetResolveStatisticsResponse
 */
async function getResolveStatistics(request: GetResolveStatisticsRequest): GetResolveStatisticsResponse {
  var runtime = new $RuntimeOptions{};
  return getResolveStatisticsWithOptions(request, runtime);
}

model ListDomainsRequest {
  pageNumber?: int32(name='PageNumber', example='1'),
  pageSize?: int32(name='PageSize', example='20'),
  search?: string(name='Search'),
  withoutMeteringData?: boolean(name='WithoutMeteringData'),
}

model ListDomainsResponseBody = {
  domainInfos?: {
    domainInfo?: [ 
    {
      domainName?: string(name='DomainName', example='www.example.com'),
      resolveHttpAes?: long(name='ResolveHttpAes'),
      resolveHttpsAes?: long(name='ResolveHttpsAes'),
      resolved?: long(name='Resolved', example='10'),
      resolved6?: long(name='Resolved6', example='20'),
      resolvedDoh?: long(name='ResolvedDoh'),
      resolvedHttps?: long(name='ResolvedHttps', example='10'),
      resolvedHttps6?: long(name='ResolvedHttps6', example='20'),
      timeModified?: long(name='TimeModified'),
    }
  ](name='DomainInfo')
  }(name='DomainInfos'),
  pageNumber?: long(name='PageNumber', example='1'),
  pageSize?: long(name='PageSize', example='5'),
  requestId?: string(name='RequestId', example='50F9C40E-188D-4208-BE2C-7427E531****'),
  totalCount?: long(name='TotalCount', example='18'),
}

model ListDomainsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListDomainsResponseBody(name='body'),
}

/**
 * @summary 列举域名以及解析统计信息
 *
 * @param request ListDomainsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListDomainsResponse
 */
async function listDomainsWithOptions(request: ListDomainsRequest, runtime: $RuntimeOptions): ListDomainsResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!$isNull(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!$isNull(request.search)) {
    query['Search'] = request.search;
  }
  if (!$isNull(request.withoutMeteringData)) {
    query['WithoutMeteringData'] = request.withoutMeteringData;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'ListDomains',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 列举域名以及解析统计信息
 *
 * @param request ListDomainsRequest
 * @return ListDomainsResponse
 */
async function listDomains(request: ListDomainsRequest): ListDomainsResponse {
  var runtime = new $RuntimeOptions{};
  return listDomainsWithOptions(request, runtime);
}

model RefreshResolveCacheRequest {
  domains?: [ string ](name='Domains'),
}

model RefreshResolveCacheShrinkRequest {
  domainsShrink?: string(name='Domains'),
}

model RefreshResolveCacheResponseBody = {
  code?: string(name='Code', description='Id of the request', example='200'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', example='FA8C2599-362D-4113-8FB4-E88A40C2****'),
}

model RefreshResolveCacheResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RefreshResolveCacheResponseBody(name='body'),
}

/**
 * @summary 刷新域名缓存
 *
 * @param tmpReq RefreshResolveCacheRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return RefreshResolveCacheResponse
 */
async function refreshResolveCacheWithOptions(tmpReq: RefreshResolveCacheRequest, runtime: $RuntimeOptions): RefreshResolveCacheResponse {
  tmpReq.validate();
  var request = new RefreshResolveCacheShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!$isNull(tmpReq.domains)) {
    request.domainsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.domains, 'Domains', 'json');
  }
  var query = {};
  if (!$isNull(request.domainsShrink)) {
    query['Domains'] = request.domainsShrink;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'RefreshResolveCache',
    version = '2016-02-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 刷新域名缓存
 *
 * @param request RefreshResolveCacheRequest
 * @return RefreshResolveCacheResponse
 */
async function refreshResolveCache(request: RefreshResolveCacheRequest): RefreshResolveCacheResponse {
  var runtime = new $RuntimeOptions{};
  return refreshResolveCacheWithOptions(request, runtime);
}

